package com.example.proxyDemo1.demo02;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 动态代理
 *  必须实现InvocationHandler接口，完成代理类要做的功能
 *  调用目标方法
 *  功能增强
 */
public class MySellHandler implements InvocationHandler {

    private Object target;

    public MySellHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object o, Method method, Object[] objects) throws Throwable {

        Object res = null;

        //执行目标方法
        res = method.invoke(target,objects);

        //进行功能增强
        if (res != null){
            Float price  = (Float) res;
            price += 25;
            res = price;
        }

        return res;
    }
}
